const routes = [
    {
        path: '/',
        redirect:'/home'
    },{
        path: "/home",
        component: Home,
        code: "home",
        name: '主页',
        children: [
            {
                path: '/home/userIndex',
                component: UserIndex,
                code: 'userIndex',
                name: "用户管理",
                children:[
                    {
                        path: '/addUserModal',
                        component: AddUserModal,
                        code: "addUserModal",
                        name: "用户添加",
                        isModal: true,
                    }, {
                        path: '/updatedUserModal',
                        component: UpdatedUserModal,
                        code: 'updatedUserModal',
                        name: "用户更新",
                        isModal: true,
                    }
                ]
            },{
                path: "/home/roleIndex",
                component: RoleIndex,
                code: "roleIndex",
                name: "角色管理",
            },{
                path: "/home/permissionIndex",
                component: PermissionIndex,
                code: "permissionIndex",
                name: "权限授予",
            },
        ]
    },{
        path: '/login',
        component: LoginIndex,
        code: 'loginIndex',
        name: '登录',
    },
];

const router = new VueRouter({
    mode: 'history',
    routes
});

// from: Route: 当前导航正要离开的路由,to: Route: 即将要进入的目标 路由对象
router.beforeEach((to, from, next) => {
    const sysUser = 'shenzonghang'//sessionStorage.getItem("sysUser");
    if(to.path==='/home'){
        if(sysUser === null || sysUser === undefined){
            next({path: '/login'});
        }else{
            next({name: '用户管理', path: '/home/userIndex'});
        }
    }
    next();
})
